package com.gxa.saas.service.impl;



import com.gxa.saas.exception.BusinessException;
import com.gxa.saas.exception.ExceptionCode;
import com.gxa.saas.mapper.UserMapper;
import com.gxa.saas.pojo.User;
import com.gxa.saas.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 *在业务层的实现类中添加Transaction注解,保证事务安全
 * @author Administrator
 */
@Service
@Transactional(rollbackFor = {Throwable.class})
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> selectByPage(Integer page) {
        return userMapper.selectByPage((page-1)*10);
    }

    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }

    @Override
    public void resetPassword(Map map) {
        userMapper.resetPassword(map);
    }

    @Override
    public List<User> selectByLikeName(Map map) {
        Integer page = (Integer)map.get("page");
        map.put("page",(page-1)*10);
        return  userMapper.selectByLikeName(map);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }
    @Override
    public void deleteUser(Integer id){
        userMapper.deleteUser(id);
    }

    @Override
    public void updateIsUsed(Map map) {
        userMapper.updateIsUsed(map);
    }

    @Override
    public Integer selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public List<User> getUserList() {
        return userMapper.getUserList();
    }

}
